[gcode_macro M204]                                                              # Set Acceleration
# Klipper accepts M204 S<value> OR M204 P<value> T<value> where both P and T must be specified
# PrusaSliser sends M204 P<value> without T and Klipper shows an error
# This macro makes M204 command more versatile
rename_existing: M204.1
gcode:
    {% set factor = params.F|default(0.5)|float %}
    {% if 'S' in params %}
        SET_VELOCITY_LIMIT ACCEL={S} ACCEL_TO_DECEL={ S|float * factor }
    {% else %}
        {% if 'P' in params %}
            {% if 'T' in params %}
                {% if P|int < T|int %}
                    SET_VELOCITY_LIMIT ACCEL={P} ACCEL_TO_DECEL={ P|float * factor }
                {% else %}
                    SET_VELOCITY_LIMIT ACCEL={T} ACCEL_TO_DECEL={ T|float * factor }
                {% endif %}
            {% else %}
                SET_VELOCITY_LIMIT ACCEL={P} ACCEL_TO_DECEL={ P|float * factor }
            {% endif %}
        {% elif 'T' in params %}
            SET_VELOCITY_LIMIT ACCEL={T} ACCEL_TO_DECEL={ T|float * factor }
        {% endif %}
    {% endif %}
